//
//  ACLiveMemberListViewController.m
//  ACLiteAVUISDK
//
//  Created by 冯琰琰 on 2021/3/30.
//

#import "ACLiveMemberListViewController.h"
#import "ACLiveMemberListCell.h"

@interface ACLiveMemberListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableview;
@property(nonatomic,strong)NSArray<TRTCLiveUserInfo *> *userList;
@end

@implementation ACLiveMemberListViewController

-(UITableView *)tableview{
    if (!_tableview) {
        _tableview = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.estimatedRowHeight = 68;
        _tableview.backgroundColor = UIColorFromRGB(0xFFFFFF);
        [_tableview setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        NSBundle *curB = [NSBundle BundleWithBundleName:ACLiteAVUISDK targetClass:[self class] ];
        [_tableview registerNib:[UINib nibWithNibName:@"ACLiveMemberListCell" bundle:curB] forCellReuseIdentifier:@"ACLiveMemberListCell"];
        _tableview.tableFooterView = [UIView new];
    }
    return _tableview;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColorFromRGB(0xF4F5F8);
    self.title = @"成员";
    
    [self.view addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(10, 0, 10, 0));
    }];
    
    self.userList = [NSArray array];
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    @weakify(self);
    [[TRTCLiveRoom shareInstance] getAudienceList:^(int code, NSString * _Nullable message, NSArray<TRTCLiveUserInfo *> * _Nonnull userList) {
        @strongify(self)
        self.userList = userList;
        [self.tableview reloadData];
    }];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.userList.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ACLiveMemberListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ACLiveMemberListCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[ACLiveMemberListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ACLiveMemberListCell"];
    }
    TRTCLiveUserInfo *liveUserInfo = self.userList[indexPath.row];
    cell.userInfo = liveUserInfo;
    [cell.cancelForbiden setHidden:YES];
    return  cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - JXCategoryListContentViewDelegate

/**
 实现 <JXCategoryListContentViewDelegate> 协议方法，返回该视图控制器所拥有的「视图」
 */
- (UIView *)listView {
    return self.view;
}
@end
